package com.motong.gongdan.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.motong.gongdan.util.LoginUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        Integer loginUserFactory = LoginUtil.getLoginUserFactory();
        //Long userId = Long.parseLong(Optional.ofNullable(UserContext.get(LoginUserConstants.USER_ID, String.class)).orElse("0"));
        this.strictInsertFill(metaObject, "factoryId", Integer.class, LoginUtil.getLoginUserFactory());
//        this.strictInsertFill(metaObject, "createUser", Long.class,0L);
//        this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());
//        this.strictInsertFill(metaObject, "updateUser", Long.class,0L);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
//        //Long userId = Long.parseLong(Optional.ofNullable(UserContext.get(LoginUserConstants.USER_ID, String.class)).orElse("0"))  ;
//        log.info("start update fill ....");
        this.strictUpdateFill(metaObject, "factoryId", Integer.class, LoginUtil.getLoginUserFactory());
//        this.strictInsertFill(metaObject, "updateUser", Long.class,0L);
    }
}
